package Pattern.FactoryPattern.workTest.Work.Program1;

abstract class Operation {
    protected int numberA;
    protected int numberB;
    // numberA和numberB的Setter方法和Getter方法

    public int getNumberA() {
        return numberA;
    }

    public void setNumberA(int numberA) {
        this.numberA = numberA;
    }

    public int getNumberB() {
        return numberB;
    }

    public void setNumberB(int numberB) {
        this.numberB = numberB;
    }

    public abstract int getResult();//-----1
}


class AddOperation extends Operation {
    public int getResult() {
        return numberA + numberB;
    }
}

class SubOperation extends Operation {
    public int getResult() {
        return numberA - numberB;
    }
}

class Calculator {
    public static Operation createOperation(char operator) {
        Operation op = null;

        switch (operator)//---------------3
        {
            case '+':
                op = new AddOperation();

                break;
            case '-':
                op = new SubOperation();
                break;
        }
        return op;
        //--------------    ;
    }
}

class Test {
    public static void main(String args[]) {
        int result;
        Operation op1 = Calculator.createOperation('+');
        op1.setNumberA(20);
        op1.setNumberB(10);
        result =op1.getResult();//------------7
        System.out.println(result);
    }
}
